package git.determinal.template.view;



import java.io.Serializable;

public class Result<T> implements Serializable {
    T data;
    int code;
    String message;

    public static <T> Result<T> result(boolean isSuccess, T data) {
        new Result();
        Result result;
        if (isSuccess) {
            result = ok(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), data);
        } else {
            result = error(StatusCode.ERROR.getCode(), StatusCode.ERROR.getMessage(), data);
        }

        return result;
    }

    public static <T> Result<T> result(boolean isSuccess, String message, T data) {
        new Result();
        Result result;
        if (isSuccess) {
            result = ok(StatusCode.SUCCESS.getCode(), message, data);
        } else {
            result = error(StatusCode.ERROR.getCode(), message, data);
        }

        return result;
    }

    public static <T> Result<T> success(T data) {
        return ok(data);
    }

    public static <T> Result<T> success(String message, T data) {
        return ok(message, data);
    }

    public static <T> Result<T> success(int code, String message, T data) {
        return ok(code, message, data);
    }

    public static <T> Result<T> ok(T data) {
        return ok(StatusCode.SUCCESS.getCode(), StatusCode.SUCCESS.getMessage(), data);
    }

    public static <T> Result<T> ok(String message, T data) {
        return ok(StatusCode.SUCCESS.getCode(), message, data);
    }

    public static <T> Result<T> ok(int code, String message, T data) {
        Result<T> result = new Result();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public static <T> Result<T> fail(T data) {
        return error(data);
    }

    public static <T> Result<T> fail(String message, T data) {
        return error(message, data);
    }

    public static <T> Result<T> fail(int code, String message) {
        return error(code, message);
    }

    public static <T> Result<T> fail(int code, String message, T data) {
        return error(code, message, data);
    }

    public static <T> Result<T> error(T data) {
        return error(StatusCode.ERROR.getCode(), StatusCode.ERROR.getMessage(), data);
    }

    public static <T> Result<T> error(String message, T data) {
        return error(StatusCode.ERROR.getCode(), message, data);
    }

    public static <T> Result<T> error(int code, String message) {
        return error(code, message, null);
    }

    public static <T> Result<T> error(int code, String message, T data) {
        Result<T> result = new Result();
        result.setCode(code);
        result.setMessage(message);
        result.setData(data);
        return result;
    }

    public Result() {
    }

    public T getData() {
        return this.data;
    }

    public int getCode() {
        return this.code;
    }

    public String getMessage() {
        return this.message;
    }

    public void setData(final T data) {
        this.data = data;
    }

    public void setCode(final int code) {
        this.code = code;
    }

    public void setMessage(final String message) {
        this.message = message;
    }

    public boolean equals(final Object o) {
        if (o == this) {
            return true;
        } else if (!(o instanceof Result)) {
            return false;
        } else {
            Result<?> other = (Result)o;
            if (!other.canEqual(this)) {
                return false;
            } else if (this.getCode() != other.getCode()) {
                return false;
            } else {
                Object this$data = this.getData();
                Object other$data = other.getData();
                if (this$data == null) {
                    if (other$data != null) {
                        return false;
                    }
                } else if (!this$data.equals(other$data)) {
                    return false;
                }

                Object this$message = this.getMessage();
                Object other$message = other.getMessage();
                if (this$message == null) {
                    if (other$message != null) {
                        return false;
                    }
                } else if (!this$message.equals(other$message)) {
                    return false;
                }

                return true;
            }
        }
    }

    protected boolean canEqual(final Object other) {
        return other instanceof Result;
    }

    public int hashCode() {
        boolean PRIME = true;
        int result = 1;
        result = result * 59 + this.getCode();
        Object $data = this.getData();
        result = result * 59 + ($data == null ? 43 : $data.hashCode());
        Object $message = this.getMessage();
        result = result * 59 + ($message == null ? 43 : $message.hashCode());
        return result;
    }

    public String toString() {
        return "Result(data=" + this.getData() + ", code=" + this.getCode() + ", message=" + this.getMessage() + ")";
    }
}




